	package com.shop2cn.iapi.wxcomponent.testcase;

import java.util.List;
import java.util.Optional;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.wxcomponent.parameter.GetMchAppFailReasonBean;
import com.shop2cn.iapi.wxcomponent.service.GetMchAppFailReasonCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.Auditrecord;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
/**
*查询小程序审核失败原因
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMchAppFailReason{
	private static GetMchAppFailReasonBean getmchappfailreasonBean;
	private static GetMchAppFailReasonCall getmchappfailreasonCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询小程序审核失败原因");
	}

	@Before
	public void caseUp() {
		getmchappfailreasonBean=new GetMchAppFailReasonBean();
		getmchappfailreasonCall=new GetMchAppFailReasonCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmchappfailreasonCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMchAppFailReason_001() {
		Logger.start(true,"查询小程序审核失败原因");
		try {
			getmchappfailreasonBean.setMchId(500009815);
			getmchappfailreasonCall.setData(getmchappfailreasonBean);
			getmchappfailreasonCall.callService();			
			Logger.verifyEquals("200", getmchappfailreasonCall.getString("code"), "验证返回code");
			List<Auditrecord> info = new DefGodMchWapper().selectAuditrecordByExample(getmchappfailreasonBean.getMchId());
			Logger.debug(FormatUtil.beanToGSONString(info));
			JsonObject ja = getmchappfailreasonCall.getJsonObject().get("data").getAsJsonObject();
			Integer id=ja.get("auditRecordId").getAsInt();
			Auditrecord auditinfo = info.stream().filter(audit->audit.getAuditRecordId().equals(id)).findAny().get();
			if(!ja.get("reason").isJsonNull()) {
				Logger.verifyEquals(ja.get("reason").getAsString(), auditinfo.getReason(), "验证reason");
			}
			if(!ja.get("screenShot").isJsonNull()) {
				Logger.verifyEquals(ja.get("screenShot").getAsString(), auditinfo.getScreenShot(), "验证screenShot");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetMchAppFailReason_002() {
		Logger.start(true,"不输入mchid失败");
		try {
			getmchappfailreasonCall.setData(getmchappfailreasonBean);
			getmchappfailreasonCall.callService();			
			Logger.verifyEquals("400", getmchappfailreasonCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetMchAppFailReason_003() {
		Logger.start(true,"输入mchid错误失败");
		try {
			getmchappfailreasonBean.setMchId(-1);
			getmchappfailreasonCall.setData(getmchappfailreasonBean);
			getmchappfailreasonCall.callService();			
			Logger.verifyEquals("400", getmchappfailreasonCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}